//
//  CoinAddressViewModel.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/6/25.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class CoinAddressViewModel: BaseViewModel {
    @objc dynamic  var refreshBool = false //监听的状态
    
    var selectBool = false //是否选择地址
    var dataArr:Array<CoinNumberModel> = []
    lazy var addressRequest: AddressNumRequest = {
        let api = AddressNumRequest()
        api.dataReformer = self
        api.paramSource = self
        api.delegate = self
        return api
    }()
    
    func archiveAddressNumber() {
        CYMBShow.openIndicator(message: nil, view: self.controller?.view)
        self.request(request: addressRequest, success: {[weak self] (result) in
            CYMBShow.colseIndicator(view:self?.controller?.view)
            self?.dataArr.removeAll()
            guard let dic = result else {
                return
            }
            guard let array = dic["data"] as? [[String:Any]] else {
                return
            }
            for smalDic in array {
                let model = CoinNumberModel(JSON: smalDic)
                if model != nil {
                    self?.dataArr.append(model!)
                }
            }
            self?.refreshBool = true
 
        }) { (response) in
            CYMBShow.colseIndicator(view: self.controller?.view)
        }
    }
    
}
extension CoinAddressViewModel: RequestCallBack,RequestDataReformer,RequestParamSource {
    func reform(_ request: BaseRequest, _ data: [String : Any]?) {
        if successBlock != nil {
            successBlock!(data)
        }
    }
    
    func requestDidSucess(_ request: BaseRequest) {
        
    }
    
    func requestDidFail(_ request: BaseRequest) {
        if failBlock != nil {
            failBlock!(request)
        }
    }
    
    func requestParams(_ request: BaseRequest) -> [String : Any]? {
        let pramas: [String:Any] = [:]
        
        return pramas
    }
    
    
    
}

